/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var oldClearDate ="";
var productInferTransfer = {
	key : null,
	dataCache : null,
	startDiv : null,
	startEvent : function() {
		productInferTransfer.showInfo();

		comValidform = $(".com-addForm").Validform(
		{
			datatype : {
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/,
				"timestamp":/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}/
			},
			tiptype : 2,
			tipSweep : true,
			beforeSubmit : function(curform) {

				var id = $('input[name="id"]').val();
				var startDiv = $('select[name="startDiv"]').val();
				var proDividStartDate = $('input[name="proDividStartDate"]').val();
				var proDividendDate = $('input[name="proDividendDate"]').val();
				var clearDate = $('input[name="clearDate"]').val();
				var url = 'mgr/ProductInfoCtrl/transfer';
				var params = {
					'id' : id,
					'startDiv' : startDiv,
					'proDividStartDate' : proDividStartDate,
					'proDividendDate' : proDividendDate,
					'clearDate' : clearDate
				};
				var cb = function(data) {
					alert(data.msg);
					// 成功返回
					if (data.resultCode == 200) {
						localStorage
								.removeItem(productInferTransfer.key);

						var singleObj = data.result;

						localStorage.setItem(singleObj.id
								+ "_ProductType02_Key", JSON
								.stringify(singleObj));
						// 关闭窗口并刷新数据
						art.dialog.close();
						returnStatus = true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},

	showInfo : function() {

		var id = art.dialog.data('transferProId');
		productInferTransfer.key = id + "_ProductType02_Key";

		var ret = eval('(' + localStorage.getItem(productInferTransfer.key)+ ')');

		var proDividendDate = (new Date(ret.proDividendDate)).format('yyyy-MM-dd');

		var proDividStartDate = (new Date(ret.proDividStartDate)).format('yyyy-MM-dd');

		var clearDate =(ret.clearDate ==null)? "": (new Date(ret.clearDate)).format('yyyy-MM-dd hh:mm:ss');
        oldClearDate = clearDate;

		$('select[name="startDiv"]').val(ret.startDiv);

		$('input[name="id"]').val(id);
		
		$('input[name="proDividendDate"]').val(proDividendDate);

		$('input[name="proDividStartDate"]').val(proDividStartDate);

        $('input[name="clearDate"]').val(clearDate);
		productInferTransfer.startDiv = ret.startDiv;

	},
	init : function() {
		productInferTransfer.startEvent();
	}
}
$(document).ready(function() {
	productInferTransfer.init();
});
function submitForm() {
    var newClearDate = $("#clearDate").val();
    var r = true;
    if(newClearDate != oldClearDate){
    	r = confirm("本次操作将改变产品的预计清算时间，确定修改吗？");
	}
	if(r == true){
        if (productInferTransfer.startDiv == 0 ) {
            comValidform.submitForm();
        } else {
            alert("产品已起标，不能再次起标");
        }
	}

	return returnStatus;
}